//
//  TopView.m
//  14-HomeWork
//
//  Created by dllo on 16/8/2.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "TopView.h"
#import "TopCollectionViewCell.h"
#define COLORAUTO [UIColor colorWithRed:(arc4random() % 256 / 255.0) green:(arc4random() % 256 / 255.0 )blue:(arc4random() % 256 / 255.0) alpha:1.0]

@interface TopView ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong)UICollectionView *collectionView;
@end
@implementation TopView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatcollection:self.bounds];
    }
    return self;
}

- (void)creatcollection:(CGRect)sender {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(self.bounds.size.width , (self.bounds.size.height - 40) / 3);
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 5;
    // UICollectionViewScrollDirectionHorizontal
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(5, 5, self.bounds.size.width, self.bounds.size.height) collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_collectionView];
    [_collectionView registerClass:[TopCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 6;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
   TopCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    //cell.contentView.backgroundColor = COLORAUTO;
    return cell;
}





@end
